package com.tpshion.cloud.auth.domain.dto;

import com.tpshion.cloud.common.support.Constants;
import org.springframework.util.StringUtils;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

@Valid
public class AddUserDto {

    @Size(min = 3,max = 20,message = "账号长度大于3位小于20位")
    @NotEmpty(message = "账号不能为空")
    private String account;

    @Size(min = 2,max = 20,message = "用户名长度大于3位小于20位")
    private String username;

    @Pattern(regexp = Constants.PHONE_REGEXP, message = "手机号不正确")
    private String phone;

    @Pattern(regexp = Constants.EMAIL_REGEXP, message = "邮箱不正确")
    private String email;

    @NotEmpty(message = "密码不能为空")
    @Size(max = 20,min = 6, message = "密码长度大于6位小于20位")
    private String password;

    private String state;

    private String note;

    private String roleId;

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    @Override
    public String toString() {
        return "AddUserDto{" +
                "account='" + account + '\'' +
                ", username='" + username + '\'' +
                ", phone='" + phone + '\'' +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                ", state='" + state + '\'' +
                ", note='" + note + '\'' +
                ", roleId='" + roleId + '\'' +
                '}';
    }

    public void init(){
        this.account = StringUtils.isEmpty(this.account) ? this.account : this.account.trim();
        this.password = StringUtils.isEmpty(this.password) ? this.password : this.password.trim();
        this.phone = StringUtils.isEmpty(this.phone) ? this.phone : this.phone.trim();
        this.email = StringUtils.isEmpty(this.email) ? this.email : this.email.trim();
        this.username = StringUtils.isEmpty(this.username) ? this.username : this.username.trim();
    }
}
